package myNewProject.repository;


import myNewProject.utils.CustomResult;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

public class StoreByNewFile implements Repository {
    private static final String FILE = "src/main/java/myNewProject/parsedResult.txt";

    @Override
    public void outPut(List<CustomResult> parsedResult) {
        StringBuilder result = new StringBuilder();
        for (CustomResult c : parsedResult) {
            result.append(c.toString()).append('\n');
        }
        FileWriter fileWriter;
        try {
            fileWriter = new FileWriter(FILE);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        try (BufferedWriter out = new BufferedWriter(fileWriter)) {
            out.write(String.valueOf(result));
        } catch (IOException e) {
            throw new RuntimeException();
        }
        System.out.println("已将所有结果保存至" + FILE);
    }


}
